package JUC.CompletableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author CKC
 * @date 2022/11/23 17:34
 */
public class DemoTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName());
            return "123";
        }, executorService).thenApplyAsync((value) -> {
            System.out.println(Thread.currentThread().getName() + "   " + value);
            return value + "56";
        }).handle((value, throwable) -> {
            System.out.println(Thread.currentThread().getName() + "   " + value);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return value + "78";
        });
        Thread.sleep(3000);
        executorService.shutdown();
    }
}
